package 二叉树.顺序存储二叉树;

public class ThreadedBinaryTreeDemo {
    public static void main(String[] args) {
        int[] arr1 = {};
        int[] arr= {1 ,2 ,3 ,4 ,5 ,6 ,7};
        ArrBinaryTree arrBinaryTree = new ArrBinaryTree(arr);
        arrBinaryTree.preOrder(0);
        for (int i = 0; i < arr.length; i++) {

        }

    }
    static class ArrBinaryTree{
        private int[] arr;

        public ArrBinaryTree(int[] arr) {
            this.arr = arr;
        }
        /**
         * @param index 数组下标
         */
        public void preOrder(int index){
            if (arr == null||arr.length ==0){
                System.out.println("数组为空，不能按照二叉树前序遍历");
            }
            System.out.println(arr[index]);

            if (index * 2 + 1 <arr.length){
                preOrder(2 * index + 1);
            }
            if((index * 2 + 2) < arr.length) {
                preOrder(2 * index + 2);
            }
        }
    }

}
